package com.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import com.entity.Product;
import com.service.ProductService;

@Controller
public class ProductController {
	@Resource
	private ProductService ps;
	@Resource
	private HttpServletRequest request;
	@RequestMapping("finproduct")
	@Transactional
	public ModelAndView findAll1(Model model){
		
		List<Product> list=ps.allProduct();
		
		model.addAttribute("list", list);
		
		ModelAndView mv=new ModelAndView("/shop.jsp");
		
		mv.addObject("list", list);	
		return mv;
	}
	@RequestMapping("productPage")
	public String peoductPage(Model model){
		String pagea=request.getParameter("page");
		int page=Integer.parseInt(pagea);
		
		int sum=ps.getcount();
		if(page>sum){
			page=sum;
		}
		List<Product> list=ps.getPage(page);
		model.addAttribute("sum", sum);
		model.addAttribute("page", page);
		model.addAttribute("list", list);
		return "/shop.jsp";
	}
}
